<?php  
        session_start();
        require('../Model/mysql.php');
        require('../host_config.php');
		if (!isset($_SESSION['shopid']) && isset($_SESSION['flag'])) {
            echo "<script language='javascript'>";
            echo "alert('You have no permission to read this page!');";
            echo "history.back();";
            echo "</script>";
            header("location:../login.php");
		}else if($_SESSION['flag'] == "2") {	
			
		}else if($_SESSION['shopid'] != $_GET['id']) {
        	header("location:select.php?id=".$_SESSION['shopid']."&flag=".$_SESSION['flag']);
        }
        $shopid = $_GET['id'];
        
        $mysql = new MySQL();
        $link = $mysql->connect($mysql_host, $mysql_user, $mysql_passwd, $mysql_db);
        $shopid = mysql_real_escape_string($shopid);
        
        header("refresh:10");
?>
<!DOCTYPE html>
<html>

<head>
<meta name="viewport" content="width=device-width; text/html; charset=utf-8" http-equiv="Content-Type">
<title>訂位資訊</title>
<link href="../mobile.css" rel="stylesheet" type="text/css">
</head>

<body>

<div id="banner">
	訂位資訊
	<div id="home">
		<a href="select.php?id=<?php echo $shopid;?>">
		<img alt="" class="auto-style1" height="40" src="../pic/home.png" width="40"></a>
	</div>
	<div id="logout">
		<a href="../logout.php">
		<img alt="" class="auto-style1" height="41" src="../pic/logout.png" width="41"></a>
	</div>
</div>

<div id="content">
	<br/>
	<H1 align="center">目前可訂位名單</H1>
    <form method="post" action="del_client.php?id=<?php echo $shopid; ?>">
        <table border='1' align='center'><tr align='center'>
            <td>刪除</td>
			<!-- <td>店家名稱</td> -->
			<td>客戶名稱</td>
			<td>訂位人數</td>
			<td>電話號碼</td>
			<td>訂位時間</td>
            </tr>
        	<?php
            	/*
            	$sql = "select all_name from android where id = '$shopid'";
            	$str = $mysql->query_row($sql, $link);
            	//$sql = "SELECT * FROM client where ShopName = '$str[0]'";
            	*/
            	//$sql = "SELECT `clientid`, `clientname`, `orderofnum`, `cellphone`, `ordertime`, `gcm_regid` FROM `Client` WHERE `shopid` = '$shopid' AND `flag` = '0'";
                $sql = "SELECT staid, clientname, orderofnum, cellphone, ordertime FROM DiningRecord WHERE shopid = '$shopid'";
            	$result = $mysql->query($sql, $link);
            
            	$message = "有位置";
           	
            	while ($row = mysql_fetch_row($result)) {
            		echo '<td><input type="radio" name="delid" value="'.$row[0].'"></td>';
                	for ($i = 1; $i < mysql_num_fields($result); $i++) {   
                		echo "<td>".$row[$i]."</td>";
                	}
                	//GCM alert
                	//$regId = $row[$i];
                	//if($row[$i] != NULL) 	      
                    //	echo '<td><input type="button" value="通知" onclick="self.location.href=\'../gcm/send_message.php?id='.$shopid.'&regId='.$regId.'&message='.$message.'\'"></td>';
                	echo "</tr>";            
            	}
            ?>
		</table>
        <p align="center"><input type="submit" value="del"></p>
	</form>
        
    <H1 align="center">排隊訂位名單</H1>
    <form method="post" action="queue_checkin.php?id=<?php echo $shopid; ?>">
    	<table border='1' align='center'><tr align='center'>
    		<!-- <td>解除排隊</td> -->
    		<td>加入訂位</td>
    		<!-- <td>店家名稱</td> -->
    		<td>客戶名稱</td>
    		<td>訂位人數</td>
    		<td>電話號碼</td>
    		<td>訂位時間</td>
    		</tr>
    		<?php
            	
            	/*
            	$sql = "select all_name from android where id = '$shopid'";
            	$str = $mysql->query_row($sql, $link);
            	//$sql = "SELECT * FROM queue where ShopName = '$str[0]'";
            	*/
            	$sql = "SELECT `clientid`, `clientname`, `orderofnum`, `cellphone`, `ordertime`, `gcm_regid` FROM `Client` WHERE `shopid` = '$shopid' AND `flag` = '-1'";
            	$result = $mysql->query($sql, $link);
            
            	while ($row = mysql_fetch_row($result)) {
            		echo '<td><input type="radio" name="clientid" value="'.$row[0].'"></td>';
                	for ($i = 1; $i < mysql_num_fields($result) -1; $i++) {
                		echo "<td>".$row[$i]."</td>";
					}
             
                //echo '<td><input type="submit" value="加入"></td>';
                	echo "</tr>";
            	}
            ?>
        </table>		
        <p align="center"><input type="submit" value="加入"></p>
	</form>
	<p align="center"><a href="del_client_list.php?id=<?php echo $shopid;?>">取消訂位名單</a>
	<p align="center">回到<a href="test.php?id=<?php echo $shopid;?>">訂位人數</a></p>
	<br />
</div>
</body>

</html>
